import request from "../../utils/request"
import {config,constVAR} from "../../config"
import { url } from "../../utils/util"

Page({
  data: {
    user_avatar: "",
    bot_avatar: "",
    messages: [
        {
           id: 1, 
           text: '你好！有事吗？啊手动阀手动阀，啊手动阀阿斯弗，大师傅阿斯弗二啊手动阀阿道夫阿斯弗，啊手动阀昂饭',
           user: 1,
         },
         {
             id: 2, 
             text: '你好！啊手动阀，啊手动阀啊手动阀，阿拉拉，饿哦安东发生的覅啊手动阀，上的飞机啊是否为暗室逢灯，傲气偶爱的',
             user: 0,
         }
    ],
    isVoice: false,
    inputValue: ''
  },
  onLoad(options) {
    let data = getApp().globalData.user
    debugger
    this.setData({
      user_avatar: url(data.avatar),
      bot_avatar: url(data.agent_icon),
    })
    request.post(config.route.begin,{
      user_id: data.openid,
      name: data.name,
      bot_id: data.agent_bot,
      avatar: data.avatar,
      platform: data.channel
    }).then(res => {
      debugger
      console.log(res)
    })
  },
  // 切换语音和文本输入
  toggleVoice() {
    this.setData({ isVoice: !this.data.isVoice });
  },

  // 监听文本输入
  onInput(e) {
    this.setData({ inputValue: e.detail.value });
  },

  // 发送消息
  sendMessage() {
    if (!this.data.inputValue.trim()) return;
    const newMessage = {
      id: Date.now(),
      text: this.data.inputValue,
      isUser: true,
    };
    
    this.setData({
      messages: [...this.data.messages, newMessage],
      inputValue: ''
    });
  }
});